import axios from 'axios';
import { AxiosResponse } from 'axios';
import qs from 'query-string';

export interface Region {
  id: number;
  name: string;
  code: string;
  parentId: number;
  level: number;
  [key: string]: any;
}

export interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
}

/**
 * 获取所有省份
 */
export function getProvinces(): Promise<AxiosResponse<ApiResponse<Region[]>>> {
  return axios.get('/api/region/provinces');
}

/**
 * 获取指定省份的所有城市
 * @param provinceId 省份ID
 */
export function getCities(provinceId: number): Promise<AxiosResponse<ApiResponse<Region[]>>> {
  return axios.get(`/api/region/cities/${provinceId}`);
}

/**
 * 获取指定城市的所有区县
 * @param cityId 城市ID
 */
export function getDistricts(cityId: number): Promise<AxiosResponse<ApiResponse<Region[]>>> {
  return axios.get(`/api/region/districts/${cityId}`);
}

/**
 * 获取指定区县的所有片区
 * @param districtId 区县ID
 */
export function getAreas(districtId: number): Promise<AxiosResponse<ApiResponse<Region[]>>> {
  return axios.get(`/api/region/areas/${districtId}`);
} 